<template>
  <div class="main-right">
    <p class="name">{{ list.name }}</p>
    <p class="desc">{{ list.desc }}</p>
    <div class="money">
      <p class="price">
        ￥<span>{{ list.price }}</span>
      </p>
      <p class="oldPrice">
        ￥<span>{{ list.oldPrice }}</span>
      </p>
    </div>
    <div class="service">
      <dl>
        <dt>促销</dt>
        <dd>12月好物放送，App领券购买直降120元</dd>
      </dl>
      <dl>
        <dt>配送</dt>
        <dd class="city">
          <span class="zhi">至</span>
          <div class="block">
            <el-cascader
              v-model="value"
              :options="options"
              size="mini"
              @change="handleChange"
            >
            </el-cascader>
          </div>
        </dd>
      </dl>
      <dl>
        <dt>服务</dt>
        <dd class="xq-list">
          <span>无忧退货</span>
          <span>快速退款</span>
          <span>免费包邮</span>
          <a>了解详情</a>
        </dd>
      </dl>
    </div>
    <div class="sku">
      <dl class="specs" v-for="(item,index) in list.specs" :key="index+1">
        <dt>{{item.name}}</dt>
        <dd>
          <img v-for="(items,indexs) in item.values" :key="indexs" :class="indexs == flag?'active':''" @click="active(index,indexs)"   :src="items.picture" v-show="items.picture != null">
          <span ref="span" v-for="(items,indexs) in item.values" :key="indexs" :class="{'active':sel[index] == indexs} " @click="active1(index,indexs)" v-show="items.picture == null">{{items.name}}</span>
        </dd>
      </dl>
    </div>
    <div class="number">
      <p>数量</p>
      <el-input-number size="mini" v-model="num" @change="onNum" :min="1" :max="10" label="描述文字"></el-input-number>
    </div>
    <button @click="Shop()" class="btn">加入购物车</button>
  </div>
</template>

<script>
import { addShop } from "../../../api/part";
import { regionData } from "element-china-area-data";
export default {
  name: "MainRight",
  props: ["list"],
  data() {
    return {
      value: [],
      options: regionData,
      num: 1,
      flag:'',
      flag1:'',
      sel:[],
      name:'',
      cm:'',
      id:""
    };
  },
  methods: {
    handleChange(value) {
      console.log(value);
    },
    fn() {
      console.log(this.list);
    },
    onNum(value) {
        console.log(value);
    },
    active(index,indexs){
      this.flag = indexs;
      this.name = this.list.specs[index].values[indexs].name;
      console.log("111",this.$refs.span[indexs].innerHTML);
      console.log(this.name);
    },
    active1(index,indexs){
      this.$set(this.sel, index, indexs)
      this.name = this.list.specs[index].values[indexs].name;
      this.cm = this.$refs.span[indexs].innerHTML;
      console.log("111",this.$refs.span[indexs].innerHTML);
      console.log("222",this.list.specs[index].values[indexs].name);
    },
    Shop(){
      let a = this.list.skus;
      for(var i=0;i<a.length;i++){
        if(a[i].specs[0].valueName == this.cm && a[i].specs[1].valueName == this.name){
          this.id = a[i].id;
          console.log(this.id)
        }
      }
      addShop(this.id,this.num).then((res) => {
        if(res.status == 200){
          this.$message({
            message: '恭喜你，这是一条成功消息',
            type: 'success'
          });
        }else{
          this.$message({
            message: '请选中',
            type: 'warning'
          });
        }
      })
    }
  },
};
</script>

<style lang="scss" scoped>

.main-right {
  .name {
    font-size: 22px;
    color: #333;
  }
  .desc {
    color: #999;
    margin-top: 10px;
  }
  .money {
    display: flex;
    margin-top: 10px;
    .price {
      color: #cf4444;
      span {
        font-size: 22px;
      }
    }
    .oldPrice {
      color: #999;
      text-decoration: line-through;
      font-size: 16px;
      margin: 3px 0 0 10px;
    }
  }
  .service {
    background: #f5f5f5;
    width: 500px;
    padding: 20px 10px 1px 10px;
    margin-top: 10px;
    dl {
      margin-bottom: 20px;
      display: flex;
      font-size: 14px;
      line-height: 28px;
      dt {
        width: 50px;
        color: #999;
      }
      .city {
        display: flex;
        .zhi {
          margin-right: 10px;
        }
      }
      .xq-list{
        span{
            margin-right: 10px;
        }
        span::before{
            content: "•";
            color: #27ba9b;
            margin-right: 2px;
        }
        a{
            color: #27ba9b;
        }
      }
      
    }
  }
}
.sku{
    padding-top: 20px;
  .specs{
    display: flex;
    align-items: center;
    dt{
      width: 50px;
      color: #999;
      font-size: 14px;
      line-height: 28px;
      text-align: center;
    }
    dd{
      width: 570px;
      color: #666;
      line-height: 40px;
      img{
        width: 50px;
        height: 50px;
        margin-bottom: 5px;
        border: 1px solid #e4e4e4;
        margin-right: 10px;
        cursor: pointer;
      }
      .active{
        border:1px solid #27ba9b;
      }
      span{
        display: inline-block;
        height: 30px;
        line-height: 28px;
        padding: 0 20px;
        border: 1px solid #e4e4e4;
        margin-right: 10px;
        cursor: pointer;
        font-size: 12px;
      }
    }
  }
}
.number{
  display: flex;
  align-items: center;
  margin-top: 20px;
  p{
    width: 50px;
    color: #999;
    font-size: 14px;
    line-height: 28px;
    text-align: center;
  }
}
.btn{
  border-color: #27ba9b;
  background: #27ba9b;
  color: #fff;
  width: 180px;
  height: 50px;
  font-size: 16px;
  outline: none;
  text-align: center;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 20px;
}
</style>